package com.gabriel.view;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

public class Processador extends JPanel {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;
	JLabel						lblProcessando		= new JLabel("Processando:");
	JLabel						lblId				= new JLabel("ID");
	private final JLabel		lblProcessador		= new JLabel("Core:");
	private final JLabel		lblX				= new JLabel("X");

	public Processador(int id) {
		initComponents();
		lblX.setText(id + "");
	}

	private void initComponents() {
		setSize(100, 100);
		setLayout(new FormLayout(new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("default:grow"), }));

		add(lblProcessador, "2, 2, default, bottom");

		add(lblX, "4, 2, default, bottom");

		add(lblProcessando, "2, 4, default, top");
		add(lblId, "4, 4, default, top");
		setBorder(new EtchedBorder());
	}

	public void processar(Processo proc) {
		new Thread(proc).start();
	}

	public void setProcessando(long id) {
		if (id >= 0) {
			lblId.setText(id + "");
		} else {
			lblId.setText("<html><font color=red>Parado!</font></html>");
		}
	}

}
